﻿<%@ Page Title="" Language="C#" MasterPageFile="~/source/masterpage/base.Master"
    AutoEventWireup="true" CodeBehind="SupplierManagement.aspx.cs" Inherits="QLK.Web.SupplierManagement" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <script language="javascript">

        function SelectAllCheckboxesSpecific(spanChk) {
            var IsChecked = spanChk.checked;
            var Chk = spanChk;
            Parent = document.getElementById('GridSupplier');
            var items = Parent.getElementsByTagName('input');
            for (i = 0; i < items.length; i++) {
                if (items[i].id != Chk && items[i].type == "checkbox") {
                    if (items[i].checked != IsChecked) {
                        items[i].click();
                    }
                }
            }
        }
        //or
        function SelectAllCheckboxes(spanChk) {
            var oItem = spanChk.children;
            var theBox = (spanChk.type == "checkbox") ? spanChk : spanChk.children.item[0];
            xState = theBox.checked; // trang thai cua checkbox
            elm = theBox.form.elements;

            for (i = 0; i < elm.length; i++)
                if (elm[i].type == "checkbox" && elm[i].id != theBox.id) {
                if (elm[i].checked != xState) elm[i].click(); // check toan bo thuoc tinh con
            }
        }

        function HighlightRow(chkB) {
            var IsChecked = chkB.checked;
            if (IsChecked) {
                chkB.parentElement.parentElement.style.backgroundColor = '#eee8aa'; //doi mau nen cua row #228b22
                chkB.parentElement.parentElement.style.color = 'white'; //doi font chu cua trong row

            }
            else {
                chkB.parentElement.parentElement.style.backgroundColor = 'white';
                chkB.parentElement.parentElement.style.color = 'black';
            }
        }

        function MouseEvents(objRef, evt) {
            var checkbox = objRef.getElementsByTagName("input")[0];
            if (evt.type == "mouseover") {
                objRef.style.backgroundColor = "orange";
            }
            else {
                if (checkbox.checked)//doi mau row khi checkbox cua dong da duoc check
                {
                    objRef.style.backgroundColor = "tomato";
                }
                else if (evt.type == "mouseout") {
                    if (objRef.rowIndex % 2 != 0)//neu index cua row la so le
                    {
                        //doi mau xen ke giua cac dong
                        objRef.style.backgroundColor = "#FFFBD6";
                    }
                    else////neu index cua row la so chan 
                    {
                        objRef.style.backgroundColor = "white";
                    }
                }
            }
        }
    
</script>

    <div style="margin-left: 10px">
        <asp:Button ID="btnAdd" runat="server" Text="Add" Width="100px" OnClick="btnAdd_Click" />
        <asp:GridView ID="GridSupplier" runat="server" AutoGenerateColumns="False" 
            onpageindexchanging="GridSupplier_PageIndexChanging" 
            DataKeyNames="SupplierID" CellPadding="4" ForeColor="#333333" 
            GridLines="None">
            <RowStyle BackColor="#EFF3FB" />
            <Columns>
                <asp:TemplateField HeaderText="STT">
                    <ItemTemplate>
                        <%#Get_STT()%>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="SupplierName" HeaderText="SupplierName" />
                <asp:BoundField DataField="Address" HeaderText="Address" />
                <asp:BoundField DataField="PhoneNumber" HeaderText="PhoneNumber" />
                <asp:TemplateField HeaderText="Edit">
                    <ItemTemplate>
                        <asp:ImageButton ID="imgEdit" runat="server" CommandArgument="<%# Eval(QLK.Database.Columns.SupplierID) %>"
                            CommandName="Edit" ImageUrl="/images/edit_desc.gif" OnClick="imgEdit_Click" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Check">
                    <HeaderTemplate>
                        <input id="chkAll" runat="server" onclick="javascript:SelectAllCheckboxes(this);"
                            type="checkbox" />
                    </HeaderTemplate>
                    <ItemTemplate>
                        <asp:CheckBox ID="chkSelect" runat="server" onclick="javascript:HighlightRow(this);" _SuppID='<%# Eval(QLK.Database.Columns.SupplierID) %>' />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#2461BF" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
        <br />
        <asp:Button ID="btnDelete" runat="server" OnClick="btnDelete_Click" Width="100px" Text="Delete" />
    </div>
</asp:Content>
